/**
 * 
 */
package ar.edu.unq.svnpermission.ui.model;

import java.util.ArrayList;
import java.util.List;

import ar.edu.unq.svnpermission.domain.Group;
import ar.edu.unq.svnpermission.domain.Membership;
import ar.edu.unq.svnpermission.domain.User;
import ar.unq.edu.svnpermission.homes.GroupHome;
import ar.unq.edu.svnpermission.homes.UserHome;

/**
 * @author nicolas
 *
 */
public class Members extends UseCase {

	private static final long serialVersionUID = 1L;
	private User selectedUser;

	
	/**
	 * Se encarga de obtener todos los members (Users y Groups)
	 * @return Una lista de Membership
	 * @author nicolas
	 */
	public List<Membership> getAll()
	{
		return getFixed();
	}
	
	private List<Membership> getFixed()
	{
		List<Membership> members = new ArrayList<Membership>();
		members.addAll(new Groups().getAll());
		for(User user : this.getAllUsers())
		{
			if(user!=null & user.getClass()==User.class)
			{
				members.add(user);
			}
		}
		return members;
	}
	
	
	
	public List<User> getAllUsers()
	{
		return this.getHome(User.class, UserHome.class).allInstances();
	}
	
	public void removeUser(User user)
	{
		this.getHome(User.class, UserHome.class).delete(user);
	}

	public User getSelectedUser() {
		return selectedUser;
	}

	public void setSelectedUser(User selectedUser) {
		this.selectedUser = selectedUser;
	}
	
	
	
}
